package com.zcj.demo.user.service.mapper;

import com.zcj.demo.user.domain.UserDO;
import com.zcj.demo.user.service.dto.UserDTO;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * User mapper层
 *
 * @author 自动生成
 * @date 2020-10-13 16:02:43
 */
@Component
public class UserMapper {


	public UserDTO entityToDTO(UserDO user) {
		UserDTO userDTO = new UserDTO();
		userDTO.setId(user.getId());
		userDTO.setUsername(user.getUsername());
		userDTO.setName(user.getName());
		userDTO.setPassword(user.getPassword());
		userDTO.setAvatar(user.getAvatar());
		userDTO.setEmail(user.getEmail());
		userDTO.setPhone(user.getPhone());
		userDTO.setAccess(user.getAccess());
		return userDTO;
	}


	public UserDO dtoToEntity(UserDTO userDTO, UserDO user) {
		user.setUsername(userDTO.getUsername());
		user.setPassword(new BCryptPasswordEncoder().encode(userDTO.getPassword()));
		user.setName(userDTO.getName());
		user.setAvatar(userDTO.getAvatar());
		user.setEmail(userDTO.getEmail());
		user.setPhone(userDTO.getPhone());
		return user;
	}

	public UserDO dtoToEntity(UserDTO userDTO) {
		UserDO user = new UserDO();
		user.setUsername(userDTO.getUsername());
		user.setPassword(userDTO.getPassword());
		user.setName(userDTO.getName());
		user.setAvatar(userDTO.getAvatar());
		user.setEmail(userDTO.getEmail());
		user.setPhone(userDTO.getPhone());
		return user;
	}
}
